package cn.niit.pm.service.impl;

import cn.niit.pm.dao.ContractMapper;
import cn.niit.pm.entity.Attendance;
import cn.niit.pm.entity.Contract;
import cn.niit.pm.service.ServiceInterface;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ContractServiceImpl implements ServiceInterface<Contract> {

    @Resource
    private ContractMapper mapper;

    @Override
    public PageInfo select(Contract contract, int pageSize, int pageNumber) {
        //使用PageHelper设置分页，为了安全分页，后边最好紧跟mybatis mapper方法
        //注意这里看起来似乎是属于内存分页，但其实PageHelper插件对mybatis执行流程进行了增强，属于物理分页
        PageHelper.startPage(pageSize, pageNumber);
        List<Contract> page = mapper.findByPage(contract);
        PageInfo<Contract> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @Override
    public void insert(Contract contract) {
        contract.setDelFlag(0);
        contract.setCreateUserId(1L);
        contract.setCreateUserName("Test");
        contract.setGmtCreate(new Date());
        mapper.insert(contract);
    }

    @Override
    public void update(Contract contract) {
        contract.setDelFlag(0);
        contract.setCreateUserId(1L);
        contract.setCreateUserName("Test");
        contract.setGmtCreate(new Date());
        mapper.update(contract);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public Contract selectById(Long id) {
        return mapper.selectById(id);
    }
}
